import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/admin/acl/login/login',
    method: 'post',
    data
  })
}

export function getInfo(token) {
  return request({
    url: '/admin/acl/login/info',
    method: 'get',
    params: { token }
  })
}

// 获取菜单权限数据
export function getMenu() {
  return request({
    url: '/admin/acl/login/menu',
    method: 'get'
  })
}

export function logout() {
  return request({
    url: '/admin/acl/login/logout',
    method: 'post'
  })
}

export function getList(page, limit, userQuery) {
  return request({
    url: `/admin/acl/user/list/${page}/${limit}`,
    method: 'post',
    data: userQuery
  })
}

export function getRoles() {
  return request({
    url: `/admin/acl/role/getRoles`,
    method: 'get'
  })
}

export function getUser(id) {
  return request({
    url: `/admin/acl/user/getUser/${id}`,
    method: 'get'
  })
}

export function getUserByName(username) {
  return request({
    url: `/admin/acl/user/getUserByName/${username}`,
    method: 'get'
  })
}

export function remove(index) {
  return request({
    url: `/admin/acl/user/remove/${index}`,
    method: 'delete'
  })
}

export function save(user) {
  return request({
    url: `/admin/acl/user/save`,
    method: 'post',
    data: user
  })
}

export function update(user) {
  return request({
    url: `/admin/acl/user/update`,
    method: 'post',
    data: user
  })
}

export function updateStatus(user) {
  return request({
    url: `/admin/acl/user/updateStatus`,
    method: 'post',
    data: user
  })
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  }
  return request({
    url: '/admin/acl/user/updatePassword',
    method: 'post',
    params: data
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/admin/acl/user/updateUserProfile',
    method: 'post',
    data: data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/admin/acl/user/uploadAvatar',
    method: 'post',
    data: data
  })
}
